package io.github.wanggit.antrpc.client.zk.zknode;

import io.github.wanggit.antrpc.commons.bean.Host;
import io.github.wanggit.antrpc.commons.bean.InterfaceNodeDataBean;
import org.apache.curator.utils.ZKPaths;

import java.util.List;

public abstract class NodeHostEntityHelper {

    public static NodeHostEntity createNodeHostEntity(String path, InterfaceNodeDataBean nodeData) {
        List<String> items = ZKPaths.split(path);
        String hostAndPort = items.get(1);
        String className = items.get(2);
        Host host = Host.parse(hostAndPort);
        NodeHostEntity hostEntity = new NodeHostEntity();
        hostEntity.setIp(host.getIp());
        hostEntity.setPort(host.getPort());
        hostEntity.setMethodStrs(nodeData.getMethods());
        hostEntity.setRegisterTs(nodeData.getTs());
        hostEntity.setMethodMap(nodeData.getMethodMap());
        hostEntity.setClassName(className);
        return hostEntity;
    }
}
